<?php
/**
 * User:chendenan
 * Created On 2022/3/20 0020 15:33
 */
namespace app\common\model\mysql;
use think\Model;
class ModelBase extends  Model{
    protected $autoWriteTimestamp = true;

    public function updateById($id,$data){
        $data['update_time'] = time();
        return $this->where(["id"=>$id])->save($data);
    }

    /**
     * 根据ID数组查询
     * @param $ids
     * @return ModelBase[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getInIds($ids){
        return $this->whereIn("id",$ids)
            ->where("status","=",config("status.mysql.table_normal"))
            ->select();
    }

    /**
     * 根据条件查询
     * @param $condition
     * @param $order
     * @return ModelBase[]|array|false|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getByCondition($condition = [],$order = ["id"=>"desc"]){
        if(!$condition || !is_array($condition)){
            return false;
        }
        $result = $this->where($condition)
            ->order($order)
            ->select();
        return $result;
    }
}